package com.hf.research.service.impl;

import com.hf.research.entity.ResearchEntity;
import com.hf.research.openfeign.IOffice30OpenFeignService;
import com.hf.research.service.ResearchService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author zcs
 * @since 2023/10/18
 */
@Service
public class ResearchServiceImpl implements ResearchService {
    @Resource
    IOffice30OpenFeignService iOffice30OpenFeignService;

    @Override
    public List<ResearchEntity> getList() {
        return initData();
    }

    @Override
    public ResearchEntity get(Integer id) {
        List<ResearchEntity> list = initData();
        ResearchEntity research = list.stream().filter(t -> t.getId().equals(id)).findFirst().orElse(null);
        if (research != null) {
            String name = iOffice30OpenFeignService.getUserId(research.getCreateUserId());
            System.out.println("成功请求ioffice30系统");
            research.setUserName(name);
        }
        return research;
    }

    /**
     * 初始化数据
     */
    private static List<ResearchEntity> initData() {
        List<ResearchEntity> researchEntityList = new ArrayList<>();
        researchEntityList.add(new ResearchEntity().setId(1001).setTitle("有关科研的调查结果").setNote("...").setCreateUserId(841));
        researchEntityList.add(new ResearchEntity().setId(1002).setTitle("科研结果公示").setNote("...").setCreateUserId(22));
        researchEntityList.add(new ResearchEntity().setId(1003).setTitle("科研调查发起").setNote("...").setCreateUserId(74));
        researchEntityList.add(new ResearchEntity().setId(1004).setTitle("关于一带一路革命发展的主要里程碑").setNote("...").setCreateUserId(58));
        researchEntityList.add(new ResearchEntity().setId(1005).setTitle("每天进步一点点").setNote("...").setCreateUserId(63));
        return researchEntityList;
    }
}
